package com.aisino.mplearning;

import com.aisino.mplearning.utils.SqlMetaUtils;

import java.sql.*;

/**
 * @author guochuantao
 * @version 1.0
 * @description
 * @since 2024/9/6 下午4:58
 */
public class MetaData {
    public static void main(String[] args) {
        String url = "jdbc:mysql://172.19.12.222:3306/dyw_test01?useUnicode=true&characterEncoding=utf8&nullCatalogMeansCurrent=true"; // 替换为你的数据库URL
        String user = "root"; // 替换为你的数据库用户名
        String password = "sjzl@2024"; // 替换为你的数据库密码
        String tableName = "xxl_job_log"; // 替换为你想要查询的表名

        try (Connection conn = DriverManager.getConnection(url, user, password)) {
            ResultSet rs = conn.createStatement().executeQuery("select * from " + tableName + " where 1>2");
            final ResultSetMetaData md = rs.getMetaData();
            for (int i = 1; i <= md.getColumnCount(); ++i) {
                final String colname = md.getColumnName(i);
                final int precision = md.getPrecision(i);
                int columnType = md.getColumnType(i);
                String columnTypeName = md.getColumnTypeName(i);
                System.out.print("colname = " + colname + "\t");
                System.out.print("precision = " + precision + "\t");
                System.out.print("columnType = " + columnType + "\t");
                System.out.print("columnTypeName = " + columnTypeName + "\t");
                System.out.println();
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}